export class ASTNode{
    type: string;       /* 词法单元 或者 语法单元 */
    lineno: number;
    colno: number;
    
    constructor(type: string, lineno: number, colno: number){
        this.type = type;
        this.lineno = lineno;
        this.colno = colno;
    }
    toString(){
        return this.type;
    }
}

// 表达式节点
export class ExpNode extends ASTNode{
    value?: NodeValue;
    children: ASTNode[];
    constructor(type: string, lineno: number, colno: number, children:ASTNode[]){
        super(type, lineno, colno);
        this.value = undefined;
        this.children = children;
    }
}

// 标识符节点
export class IDNode extends ASTNode{
    id:string;
    constructor(type: string, lineno: number, colno: number, id:string){
        super(type, lineno, colno);
        this.id = id;
    }
}

export class OpNode extends ASTNode{
    constructor(type: string, lineno: number, colno: number){
        super(type, lineno, colno);
    }
}
export class ConstNode extends ASTNode{
    value: NodeValue;
    constructor(type: string, lineno: number, colno: number, value:NodeValue){
        super(type, lineno, colno);
        this.value = value;
    }
}

// 字符串节点
export class StringNode extends ConstNode{
    constructor( lineno: number, colno: number, value:NodeValue){
        super("String", lineno, colno,value);
    }
}
// 数字节点
export class NumberNode extends ConstNode{
    constructor( lineno: number, colno: number, value:NodeValue){
        super("Number", lineno, colno,value);
    }
}
// 布尔节点
export class BooleanNode extends ConstNode{
    constructor( lineno: number, colno: number, value:NodeValue){
        super("Boolean", lineno, colno,value);
    }
}


export class NodeValue{
    type:"string"|"number"|"boolean";
    value: string|number|boolean;
    constructor(type:"string"|"number"|"boolean", value: string|number|boolean){
        this.type = type;
        this.value = value;
    }
}